#include <vtkActor.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>

#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <vtkTransform.h>
#include <vtkAutoInit.h>

VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);  // 用于文本渲染
// VTK_MODULE_INIT(vtkFiltersCore);        // 用于基础过滤功能

int main(int, char* []) {
    // 1. 创建点坐标
    vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
    vtkIdType id0 = points->InsertNextPoint(0, 0, 0);   // 点1
    vtkIdType id1 = points->InsertNextPoint(1, 0, 0.5);   // 点2
    vtkIdType id2 = points->InsertNextPoint(0.5, 0.5, 0.5);   // 点3
    vtkIdType id3 = points->InsertNextPoint(0.5, 0.5, 0);   // 点4

    // 2. 定义点的拓扑（每个点是一个独立单元）
    vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
    for (vtkIdType i = 0; i < points->GetNumberOfPoints(); ++i) {
        vertices->InsertNextCell(1);    // 每个单元包含1个点
        vertices->InsertCellPoint(i);
    }

    // 3. 构建PolyData
    vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
    polyData->SetPoints(points);
    polyData->SetVerts(vertices);       // 用SetVerts设置点单元

    // 4. 渲染设置
    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputData(polyData);

    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetPointSize(10);  // 点大小
    actor->GetProperty()->SetColor(1, 0, 0); // 红色

    // 5. 显示窗口
    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);
    //调整摄像机位置，以适应整个视图
    renderer->ResetCamera();
    renderer->SetBackground(1, 1, 1);  // 白色背景

    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);
    renderWindow->SetSize(600, 600);

    vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetRenderWindow(renderWindow);
    interactor->Initialize();
    interactor->Start();

    return 0;
}
